import requests
from lxml import etree
import csv
from fontTools.ttLib import TTFont

# url = 'https://www.dianping.com/search/keyword/2/0_%E6%A1%8C%E7%90%83'
#
# headers = {
#     'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
#     'Cookie': 'fspop=test; _lxsdk_cuid=1798c53051bc8-0d6a8dc627490f-2363163-144000-1798c53051bc8; _lxsdk=1798c53051bc8-0d6a8dc627490f-2363163-144000-1798c53051bc8; _hc.v=7b550c18-a6e5-b3e4-f4e2-a84959469e82.1621556922; s_ViewType=10; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; thirdtoken=e0a4fb90-480d-45bd-b874-96c86624231b; _thirdu.c=5e8fc6127e6c59c2d894fe2807298b37; Hm_lvt_602b80cf8079ae6591966cc70a3940e7=1621556933,1621816972,1621817028; cy=2; cye=beijing; Hm_lpvt_602b80cf8079ae6591966cc70a3940e7=1621817105'
# }
# r = requests.get(url=url, headers=headers)
# r.encoding = 'utf-8'
#
# g = open('./dzdp.html', 'w',encoding='utf-8')
#
# g.write(r.text)
font = TTFont('./dzdp.ttf')
cmap = font.get('cmap').getBestCmap()
ttf_dict = dict()
for k, v in cmap.items():
    # print(k, v)
    content = "\\u00" + v[3:] if len(v[3:]) == 2 else "\\u" + v[3:]
    real_content = content.encode('utf-8').decode('unicode_escape')
    print(hex(k),real_content)